<template>
  <section v-loading="loading" class="cms-body">
    <div class="cms-list-header flex-between">
      <el-button type="primary" icon="el-icon-plus" @click="routerLink('/internationalCode/save','save',0)" v-perms="'/internationalCode/save'">添加</el-button>
      <!-- 右操作 -->
      <div>
        <cms-input label="区号名称" v-model="params.internationaName"></cms-input>
        <el-button @click="goQuery()">查询</el-button>
      </div>
    </div>
    <!-- 表格 -->
    <el-table :data="tableData" stripe style="width: 100%" @selection-change="checkIds">
      <el-table-column type="selection" width="35" align="center"></el-table-column>
      <el-table-column prop="id" label="id" width="60" align="center"></el-table-column>
      <el-table-column prop="internationaName" label="区号名称" width="240" align="center"></el-table-column>
      <el-table-column prop="internationaNo" label="区号" width="240" align="center"></el-table-column>
      <el-table-column prop="position" label="排列顺序" align="center">
        <div slot-scope="scope">
          <el-input v-model="scope.row.sort" type="number" class="w50"></el-input>
        </div>
      </el-table-column>
      <el-table-column label="操作" align="center" width="90">
        <div slot-scope="scope">
          <cms-button type="edit" @click.native="routerLink('/internationalCode/update','update',scope.row.id)" v-perms="'/internationalCode/update'"></cms-button>
          <cms-button type="delete" @click.native="deleteBatch($api.internationalCodeDelete,scope.row.id)" v-perms="'/internationalCode/delete'"></cms-button>
        </div>
      </el-table-column>
    </el-table>
    <!-- 表格底部 -->
    <div class="cms-list-footer">
      <div class="cms-left">
        <el-button :disabled="disabled" @click="batchUpdate($api.internationalCodeBatchUpdate)" v-perms="'/internationalCode/batchUpdate'">保存排序</el-button>
        <el-button :disabled="disabled" @click="deleteBatch($api.internationalCodeDelete,ids)" v-perms="'/internationalCode/delete'">批量删除</el-button>
      </div>
      <!-- cms分页组件 -->
      <cms-pagination :total="total" @change="getPages"></cms-pagination>
    </div>
  </section>
</template>

<script>
  import listMixins from '@/mixins/list'

  export default {
    mixins: [listMixins],
    data() {
      return {
        params: {//只需要业务参数
          pageNo: 1,
          pageSize: 10,
          internationaName: ''
        }

      };
    },
    methods: {
      goQuery() {
        this.getTableData(this.params);
      },
      batchUpdate(url) { //保存排列循序
        let params = [];
        for (let i in this.checkedList) {
          let param = this.checkedList[i];
          console.log(param)
          param['internationalId'] = param.id;
          params.push(param)
        }
        params = JSON.stringify(params);
        this.$confirm('是否保存?', '提示', {type: "warning"}).then(mes => {
          this.$http.post(url, {params: params}).then(res => {
            if (res.code == "200") {
              this.successMessage('操作成功');
              this.getTableData(this.params);
            }
          });
        }).catch(error => {
          console.log(error)
        });
      }

    },
    created() {
      this.initTableData(this.$api.internationalCodePageList, this.params);
    }
  };
</script>

<style>

</style>
